﻿using System;
using System.Collections.Generic;
using System.IO.IsolatedStorage;

namespace Amicus_Place_Finder
{
    public static class SettingUtils
    {
        public static bool IsWP8 { get { return Environment.OSVersion.Version >= TargetedVersion; } }

        private static Version TargetedVersion = new Version(8, 0);

        public static SavedSettings Settings = new SavedSettings();
        private static IsolatedStorageSettings Storage = IsolatedStorageSettings.ApplicationSettings;

        public static void LoadSettings()
        {
            foreach (var prop in Settings.GetType().GetProperties())
            {
                try
                {
                    if (Storage.Contains(prop.Name))
                    {
                        prop.SetValue(Settings, Storage[prop.Name], null);
                    }
                    else
                    {
                        Storage.Add(prop.Name, prop.GetValue(Settings, null));
                    }
                }
                catch { }
            }
        }

        public static void SaveSettings()
        {
            foreach (var prop in Settings.GetType().GetProperties())
            {
                try
                {
                    if (Storage.Contains(prop.Name))
                    {
                        Storage[prop.Name] = prop.GetValue(Settings, null);
                    }
                    else
                    {
                        Storage.Add(prop.Name, prop.GetValue(Settings, null));
                    }
                }
                catch { }
            }
        }

    }

    public class SavedSettings
    {
        public SavedSettings()
        {
            FirstTime = true;
            IsLocationServiceEnabled = true;

            MapFrom = 0;
            IsGooglePlaceEnable = true;
            IsFacebookPlaceEnable = true;
            IsFoursquarePlaceEnable = true;
            MapSearchRadius = 10000;
            ZoomLevel = 16;

            OfflinePlace = new List<PlaceItem>();
        }

        public bool FirstTime { get; set; }
        public bool IsLocationServiceEnabled { get; set; }

        public int MapFrom { get; set; }
        public bool IsGooglePlaceEnable { get; set; }
        public bool IsFacebookPlaceEnable { get; set; }
        public bool IsFoursquarePlaceEnable { get; set; }
        public int MapSearchRadius { get; set; }
        public int ZoomLevel { get; set; }

        public List<PlaceItem> OfflinePlace { get; set; }

    }
}